package src.week4.实验一;

import java.util.Arrays;

public class shuzu  {
//    private final int DEFAULT_CAPACITY = 100;
    protected int nLiWenZhou;
    int[] number;

    public shuzu(){
        number = new int[0];
        nLiWenZhou = 0;
    }
    public void add(int shuzu){
        if (size()==number.length){
            increaseSize();
        }
        number[nLiWenZhou]= shuzu;
        nLiWenZhou++;
    }
    private void increaseSize(){
        int[] temp = new int[number.length+1];
        for (int num=0;num<number.length;num++){
            temp[num]=number[num];
        }
        number=temp;
    }
    public void insert(int weizhi,int num){
        int[] temp;
        int index = number.length;
        if (index>number.length-1){
            temp = new int[number.length*3/2];
            System.arraycopy(number,0,temp,0,number.length);
            number=temp;
        }
        for (int i=index;i>weizhi;i--){
            number[i] = number[i-1];
        }
        number[weizhi] = num;
        index++;
    }
    public void delete(int weizhi){
        int index = number.length;
        index--;
        for (int i=weizhi;i<index;i++){
            number[i]=number[i+1];
        }
        number[index]= 0;
    }

    public int size(){
        return nLiWenZhou;
    }


    public  void sort(int[] arrays){
        int minIndex;
        for (int i = 0; i < arrays.length-1; i++) {
            minIndex=i;
            int minValue=arrays[minIndex];
            for (int j = i; j < arrays.length-1; j++) {

                if(minValue>arrays[j+1]){
                    minValue=arrays[j+1];
                    minIndex=j+1;
                }
            }
            if(i!=minIndex)
            {
                int temp=arrays[i];
                arrays[i]=arrays[minIndex];
                arrays[minIndex]=temp;
            }
        }
    }
//public  void selectionSort(Comparable[] list)
//{
//    int min;
//    Comparable temp;
//
//    for (int index = 0; index < list.length-1; index++)
//    {
//        min = index;
//        for (int scan = index+1; scan < list.length; scan++)
//            if (list[scan].compareTo(list[min]) < 0)
//                min = scan;
//
//        // Swap the values
//        temp = list[min];
//        list[min] = list[index];
//        list[index] = temp;
//    }
//}

//    @Override
//    public int compareTo(Object other)
//    {
//        int result;
//
//        int otherFirst = ((int)other);//.getFirstName();
//        //int otherLast = ((int)other);//.getLastName();
//
//        if (lastName.equals(otherLast))
//            result = firstName.compareTo(otherFirst);
//        else
//            result = lastName.compareTo(otherLast);
//
//        return result;
//    }

    @Override
    public String toString() {
       String result = " ";
       for (int a=0;a<size();a++){
           result+=number[a];
       }
       return result;
    }
}

